<?php
declare (strict_types=1);

namespace app\common\model;

/**
 * @mixin \think\Model
 */
class AccountBonus extends Base
{

    protected $name = 'user_account_bonus';


    public function user()
    {
        return $this->hasOne(User::class, 'id', 'uid')->field('id,code,nickname,mobile');
    }

    public function take()
    {
        return $this->hasOne(User::class, 'id', 'source')->field('id,code,nickname,mobile');
    }

    public function getTypeAttr($value)
    {
        return get_pay_way($value);
    }


    public static function _adds($id, $type, $amount, $real_amount, $intro, $fx, $source = 0, $category = 0)
    {
        try {

            parent::create([
                'uid' => $id,
                'type' => $type,
                'intro' => $intro,
                'amount' => $amount,
                'real_amount' => $real_amount,
                'fx' => $fx,
                'create_time' => time(),
                'create_date' => date('Y-m-d'),
                'source' => $source,
                'category' => $category,
            ]);

            return true;
        } catch (\Exception $e) {
            return $e->getMessage();
        }
    }


}
